package com.example.service.impl;

import com.example.mapper.pokaYokeIdentifyMapp;
import com.example.pojo.pokaYokeIdentifyPojo;
import com.example.pojo.queryResult;
import com.example.service.pokaYokeIdentifyService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.web.bind.annotation.PutMapping;

import java.time.LocalDateTime;
import java.util.List;
import java.util.Map;

/**
 * ClassName:pokaYokeIdentifyImpl
 * Description:
 *
 * @Author 赵永峰
 * @Create 2025/11/1 21:25
 * @Version 1.0
 */
@Service
public class pokaYokeIdentifyImpl implements pokaYokeIdentifyService {
    @Autowired
    private pokaYokeIdentifyMapp pokaYokeIdentifyMapp;
    //插入一条防错分析数据
    public void insertOne(pokaYokeIdentifyPojo pojo){
        //修改编辑、修改时间
        pojo.setUpdate_time(LocalDateTime.now());
        pojo.setCreate_time(LocalDateTime.now());
        pokaYokeIdentifyMapp.insertOne(pojo);
    }
    //多条件筛选防错分析表
    public queryResult filterPokaYok(Map<String, Object> map){
        queryResult queryResult=new queryResult();
        // 提取所有查询参数（共11个）
        String failure_classification = (String) map.get("failure_classification");
        String part_name = (String) map.get("part_name");
        String poka_yoke_level = (String) map.get("poka_yoke_level");
        String poka_yoke_type = (String) map.get("poka_yoke_type");
        String engine_type = (String) map.get("engine_type");
        String is_finish = (String) map.get("is_finish");
        String workshop = (String) map.get("workshop");
        String lineName = (String) map.get("lineName");
        String op = (String) map.get("op");

        // 分页参数（转换为整数）
        int currentPage = map.containsKey("currentPage") ?
                Integer.parseInt(map.get("currentPage").toString()) : 1;
        int pageSize = map.containsKey("pageSize") ?
                Integer.parseInt(map.get("pageSize").toString()) : 20;
        int startPage=(currentPage-1)*pageSize;
        //查询分页数据
        List<pokaYokeIdentifyPojo> pojos=pokaYokeIdentifyMapp.filterPokaYok(failure_classification,part_name,poka_yoke_level,poka_yoke_type,engine_type,is_finish,workshop,lineName,op,startPage,pageSize);
        queryResult.setData(pojos);
        System.out.println(pojos);
        //查未分页的总数
        Integer total=pokaYokeIdentifyMapp.filterPokaYokTotal(failure_classification,part_name,poka_yoke_level,poka_yoke_type,engine_type,is_finish,workshop,lineName,op);
        queryResult.setTotal(total);
        return queryResult;
    }
    //修改一条防错数据
    public void editOneRow(pokaYokeIdentifyPojo pojo){
        //修改时间
        pojo.setUpdate_time(LocalDateTime.now());
        pokaYokeIdentifyMapp.editOneRow(pojo);
    }
}
